home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 7 / Apprentice-Release7.iso / Source Code / C / Applications / Moscow ML 1.42 / ANSIshellƒ / os_mac_stringio.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-04-18  |  1.1 KB  |  63 lines  |  [TEXT/R*ch]

  1. /* os_mac_stringio.c */
  2. /* 14Aug93  e */
  3.  
  4. #if defined(THINK_C)
  5.  
  6. #include <MacHeaders>
  7. #include <console.h>
  8. #include <stddef.h>
  9. #include <stdlib.h>
  10. #include <errno.h>
  11. #include <ansi_private.h>
  12.  
  13. #include "os_mac.h"
  14.  
  15. static int stringio( FILE *fp, int i )
  16. {
  17.     int result = 0;
  18.     switch (i)
  19.     {    case 0:                /*  read  */
  20.             fp->eof = 0;
  21.             if ((result = fp->cnt) == 0)
  22.             {    fp->eof = 1;
  23.                 result = EOF;
  24.             }
  25.             break;
  26.         case 1:                /*  write  */
  27.             break;
  28.         case 2:                /*  close  */
  29.             break;
  30.     }
  31.     return(result);
  32. }
  33.  
  34. FILE * e_open_string_stream( char *str )
  35. {    int cnt;
  36.     FILE *fp = __getfile();
  37.  
  38.     if ( fp == NULL)
  39.         return(fp); /* ML wanted -1 */
  40.     fclose(fp);
  41.     fp->refnum = -1;
  42.     fp->window = (void *)(-1);
  43.     cnt = strlen(str);
  44.     setvbuf(fp, NULL, _IOFBF, cnt + 1 );
  45.     strcpy( fp->buf, str );
  46.     fp->ptr = (unsigned char *)fp->buf;
  47.     fp->cnt = cnt;
  48.     fp->proc = stringio;
  49.     return(fp); /* ML wanted: (int )fileno(fp) */
  50. }
  51.  
  52. #elif defined(__MWERKS__)
  53.  
  54. #include <stdio.h>
  55.  
  56. FILE * e_open_string_stream( char *str )
  57. { return stderr;                            /* help! */
  58. }
  59.  
  60. #else
  61. "unknown compiler"
  62. #endif
  63.